import './index.less';

import React from 'react';
import { observer} from 'mobx-react';

import { Button, Modal } from 'antd';
import {WeaFormItem, WeaLocaleProvider, WeaTools,WeaDialog} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
const getKey = WeaTools.getKey;

import {WeaSwitch} from "comsMobx";

/**
 * @author jh
 * @description 自主选择提醒人
 * @date 2019/1/8
 */
@observer
export default class RemindSet extends React.Component {

    constructor(){
        super();
        this.state = {
            visible : true,
            reminder : '',
            remindTypes : '',
        };
        this.onSelectChange = this.onSelectChange;
    }

    componentDidMount() {
        const { store } = this.props;
        store.getRemindData();
    }

    render() {
        const { store } = this.props;
        const { form,condition } = store;
        let { visible,reminder,remindTypes } = this.state;
        let group = [];

        if(form.isFormInit){
            const formParam = form.getFormParams();
            reminder = formParam.reminder;
            remindTypes = formParam.remindTypes;
            condition.map((c)=>{
                c.items.map((item)=>{
                    const domKey = typeof item.domkey === "object" ? item.domkey[0] : item.domkey;
                    group.push(
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@xwidg1@${domKey}`}
                            label={ item.label }
                            labelCol={{span: `${item.labelcol}`}}
                            wrapperCol={{span: `${item.fieldcol}`}}
                            tipPosition="bottom"
                        >
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@fztrla@group1`} fieldConfig={item} form={form}  onChange={(v) => {this.onSelectChange(getKey(item),v)}}/>
                        </WeaFormItem>
                    );
                });
            });
        }
        return (
            <div>
            {
                form.isFormInit && <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@m8sjx2`}
                            title = {getLabel(502764,'请确认流程提醒')}
                            visible={visible}
                            closable = {false}
                            style={{width: 600, height: 100}}
                            maskClosable={false}
                            icon = {'icon-coms-workflow'}
                             iconBgcolor = {'#0079DE'}
                            buttons={[
                                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@5kcszv@submit`} type="primary" size="large"
                                    onClick={this.submitEvent}
                                >
                                    {getLabel(826,'确定')}
                                </Button>
                            ]}
                        >
                        <div className = {'wea-req-chose-reminder-modal'}>{ group }</div>
                    </WeaDialog>
             }
            </div>
        );
    }

    /**
     *  提醒
     */
    submitEvent = () => {
        const { store } = this.props;
        const { form } = store;
        store.doRemind(form.getFormParams());
        this.setState({visible: false});
    }

    /**
     *  不提醒
     */
    cancelEvent = () => {
        const { store } = this.props;
        store.doNotRemind();
        this.setState({visible: false});

    }

    /**
     *
     * @param key
     * @param v
     */
    onSelectChange = (key,v) => {
        this.setState({
            key : v
        });
    }
}

